def get_amount():
    while True:
        amount_input = input("请输入要兑换的金额：")
        try:
            amount = float(amount_input)
            if amount <= 0:
                print("金额必须大于0，请重新输入。")
            else:
                return amount
        except ValueError:
            print("错误：请输入一个有效的数字。")

def get_currency():
    while True:
        currency = input("请输入货币类型（USD 或 CNY）：").strip().upper()
        if currency in ['USD', 'CNY']:
            return currency
        else:
            print("错误：请输入USD或CNY。")

def convert_currency(amount, currency):
    rate = 7.0
    if currency == 'USD':
        converted = amount * rate
        target_currency = 'CNY'
    else:
        converted = amount / rate
        target_currency = 'USD'
    return converted, target_currency

def main():
    print("欢迎使用汇率兑换程序！")
    print("汇率固定为1 USD = 7.0 CNY")
    
    while True:
        amount = get_amount()
        currency = get_currency()
        
        converted_amount, target = convert_currency(amount, currency)
        
        print(f"\n兑换结果：{amount:.2f} {currency} = {converted_amount:.2f} {target}\n")
        
        choice = input("是否继续操作？(y/n): ").strip().lower()
        while choice not in ['y', 'n']:
            print("无效的选择，请输入y或n。")
            choice = input("是否继续操作？(y/n): ").strip().lower()
        if choice == 'n':
            print("\n感谢使用，再见！")
            break

if __name__ == "__main__":
    main()